package com.hymall.controller.admin;

import com.hymall.bean.MarketUser;
import com.hymall.bean.common.BasePageInfo;
import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.bean.common.User;
import com.hymall.service.admin.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author stone
 * @date 2022/06/25 11:05
 */
@RestController
@RequestMapping("admin/user")
public class AdminUserController {

    @Autowired
    UserService userService;

    /*@RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit, String sort,String order) {

    }*/

  /*  @RequestMapping("list")
    //public BaseRespVo list(String username, Integer page, Integer limit, String sort, String order) {
    public BaseRespVo list(String username, BasePageInfo info) {
        CommonData<User> data =  userService.query(username,info);
        return BaseRespVo.ok(data);
    }*/


    /**
     * @return
     * @description 实现会员管理,根据用户名和电话
     */
    @RequestMapping("list")
    //public BaseRespVo list(String username, Integer page, Integer limit, String sort, String order) {
    public BaseRespVo list(String username, String mobile, BasePageInfo info) {
        CommonData<MarketUser> data =  userService.query(username,mobile,info);
        return BaseRespVo.ok(data);
    }

    /**
     * @description 会员管理中根据id查找
     * @return
     */

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){

         List<MarketUser> marketUsers = userService.selectUserById(id);
         if(marketUsers.isEmpty()){
             return BaseRespVo.ok(null);
         }

         return BaseRespVo.ok(marketUsers.get(0));
    }

    /**
     * @return 返回结果成功
     * @description 修改会员管理详情
     */
    @PostMapping("update")
    public BaseRespVo update(@RequestBody MarketUser marketUser){
        userService.updateMessage(marketUser);
        return BaseRespVo.ok(1);

    }
}
